package co.com.desarrollo.test.pedidos.config.spring;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;

import co.com.desarrollo.pedidos.services.GeneralService;
import co.com.desarrollo.pedidos.services.PedidoService;
import co.com.desarrollo.pedidos.services.ProductoService;
import co.com.desarrollo.pedidos.services.TiendaService;
import co.com.desarrollo.pedidos.services.UsuarioService;

@Configuration
public class ConfigurationTestServices {

	private @Value("#{'${rmi.ip}'}") String url;
	private @Value("#{'${rmi.port}'}") Long rmiport;
	
	@Bean
	public RmiProxyFactoryBean generalService()
	{
		RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
		rmiProxyFactoryBean.setServiceUrl("rmi://"+url+":"+rmiport+"/GeneralService");
		rmiProxyFactoryBean.setServiceInterface(GeneralService.class);
		rmiProxyFactoryBean.setLookupStubOnStartup(false);
		rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true);
		return rmiProxyFactoryBean;
	}
	
	@Bean
	public RmiProxyFactoryBean productoService()
	{
		RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
		rmiProxyFactoryBean.setServiceUrl("rmi://"+url+":"+rmiport+"/ProductoService");
		rmiProxyFactoryBean.setServiceInterface(ProductoService.class);
		rmiProxyFactoryBean.setLookupStubOnStartup(false);
		rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true);
		return rmiProxyFactoryBean;
	}
	
	@Bean
	public RmiProxyFactoryBean tiendaService()
	{
		RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
		rmiProxyFactoryBean.setServiceUrl("rmi://"+url+":"+rmiport+"/TiendaService");
		rmiProxyFactoryBean.setServiceInterface(TiendaService.class);
		rmiProxyFactoryBean.setLookupStubOnStartup(false);
		rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true);
		return rmiProxyFactoryBean;
	}
	
	@Bean
	public RmiProxyFactoryBean pedidoService()
	{
		RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
		rmiProxyFactoryBean.setServiceUrl("rmi://"+url+":"+rmiport+"/PedidoService");
		rmiProxyFactoryBean.setServiceInterface(PedidoService.class);
		rmiProxyFactoryBean.setLookupStubOnStartup(false);
		rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true);
		return rmiProxyFactoryBean;
	}
	
	@Bean
	public RmiProxyFactoryBean usuarioService()
	{
		RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
		rmiProxyFactoryBean.setServiceUrl("rmi://"+url+":"+rmiport+"/UsuarioService");
		rmiProxyFactoryBean.setServiceInterface(UsuarioService.class);
		rmiProxyFactoryBean.setLookupStubOnStartup(false);
		rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true);
		return rmiProxyFactoryBean;
	}
}
